Fix the address of the test contract #347
Merged
+21
−14
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
When running the vm_load test in foundry-polkadot, contract creation in PVM mode fails with a BadOrigin error. The root cause is that the test contract address is being incorrectly overwritten with the CREATE2 deployer address during infrastructure setup.
Symptoms
Test: vm_load
Error: Contract creation failed: BadOrigin
When: Creating a contract with new Counter(x) after calling vm.pvm(true) to switch to PVM mode
The test contract attempts to create a Counter contract in PVM, but the origin validation fails
Root Cause of the issue
The Backend::initialize() function unconditionally sets the test_contract address on every transaction, based on the transaction being executed.
The Problem Flow
Test contract deployment (in runner.rs:161):
set_test_contract(address) is called explicitly with the actual test contract address 0x7FA9385bE102ac3EAc297483Dd6233D62b3e1496
This happens early because foundry-polkadot needs to know the test contract address to skip PVM mode for test contract operations
CREATE2 deployer deployment (in runner.rs:200):
deploy_create2_deployer() is called, which deploys the CREATE2 factory at 0x4e59b44847b379578588920ca78fbf26c0b4956c (which is DEFAULT_CREATE2_DEPLOYER)
This deployment triggers Backend::initialize()
initialize() calculates the deployed contract address and calls set_test_contract() with 0x4e59b44847b379578588920ca78fbf26c0b4956c
The actual test contract address is now overwritten with the CREATE2 deployer address